<!--/**
* 登录界面*
*
* @author LWG and 张李垚
* @date 2022/7/26 15:54
* @since 1.0.0
*/-->
<template>
  <div class="login_container">
   <div class="login_box">
    <div class="avatar_box">
       <img src="../assets/log1.png" alt="">
    </div>
    <el-form :model="loginForm" label-width="0px" class="login_form">
        <el-form-item >
            <el-input v-model="loginForm.username" prefix-icon="el-icon-user"></el-input>
        </el-form-item>
        <el-form-item >
            <el-input  v-model="loginForm.password"  prefix-icon="el-icon-lock" type="password"></el-input>
        </el-form-item>
        <el-form-item class="btns">
        <el-button @click="onLogin" class="abc" type="info" style="width:110px; height:50px;">登录</el-button><!--/**按钮*/-->
        </el-form-item>
    </el-form>
   </div>
  </div>
</template>

<script>
import AboutView from './AboutView.vue';
export default {
    name: "ds",
    components: { AboutView },
    data(){
      return{
        loginForm:{
          username:'zly',
          password:'123'
        }//登录表单的数据对象
      }
  },
  methods: {
    //
      button1() {
      // console.log("分享平台数据数据")
      this.showNum = 1
      this.$router.push('/home/activityOfRegion');
    },
    // 登录按钮绑定事件
    onLogin () {
      this.$refs.userForm.validate(async valid => {
        // 如果验证失败，不发送请求 结束函数
        if (!valid) return false
        // 验证通过 是按钮进入 loading... 登录中状态
        this.loginLoading = true
        // 调用登录接口 使用await优化 拿到返回的结果
        const data = await userLogin(this.user).catch(err => {
          this.$message.error('登录失败手机号或验证码错误')
          // 登录调用完成 让按钮恢复
          this.loginLoading = false
          return err
        })
        if (data.status !== 201) return
        this.$message.success('登录成功')
        localStorage.setItem('token', data.data.data.token)
        this.$router.push({ path: '/home' })
        // 登录调用完成 让按钮恢复
        this.loginLoading = false
      })
    }
  }
}

</script>

<style lang="less" scoped>
.login_container{
  height: 100%;
  width: 100%;
  background: url("~@/assets/bcg.png")no-repeat;
  background-size: cover;
}
.login_box{
  width: 450px;
  height: 300px;
  background-color: #e9e6e6;
  border-radius: 3px;
  position: absolute;
  left: 50%;
  top:50%;
  transform: translate(-50%,-50%);
  box-shadow: 2px 2px 10px #909090;
  
  .avatar_box{
    height: 130px;
    width: 190px;
    border-radius: 90%;
    padding: 1px;
    box-shadow: 0 0 10px rgb(206, 210, 214);
    position: absolute;
    left: 50%;
    transform: translate(-50%,-50%);
    img{
      width: 100%;
      height: 100%;
      border-radius:50% ;
      background-color: #7c7b7b;
    }
    
  }
}
.login_form{
  position: absolute;
  bottom: 0;
  width: 100%;
  padding: 0 20px;
  box-sizing: border-box;
}
.btns{
  display: flex;
  justify-content: flex-end;
  width: 250px;
}
.abc{
  background-color: #7c7b7b;
}
</style>